package initialize

import (
	"context"
	"github.com/redis/go-redis/v9"
	"go-study/global"
	"log"
)

func Redis() {
	redisClient, err := initRedisClient()
	if err != nil {
		panic(err)
	}
	global.ASW_REDIS = redisClient
}

func initRedisClient() (redis.UniversalClient, error) {
	var client redis.UniversalClient
	client = redis.NewClient(&redis.Options{
		Addr:     "192.168.11.207:6379",
		Password: "Xiodi.cn123",
		DB:       0,
	})
	_, err := client.Ping(context.Background()).Result()
	if err != nil {
		log.Println("redis connect ping failed")
	}
	return client, nil
}
